package com.ruoyi.ams.controller;

import com.ruoyi.ams.domain.AmsAssetProcess;
import com.ruoyi.ams.service.IAmsAssetProcessService;
import com.ruoyi.common.core.domain.KeyValueVo;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.security.annotation.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * 流程控制Controller
 * 
 * @author yfkj
 * @date 2022-05-16
 */
@RestController
@RequestMapping("/ams/process")
public class AmsAssetProcessController extends BaseController
{
    @Autowired
    private IAmsAssetProcessService amsAssetProcessService;

    /**
     * 查询流程控制列表
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:process:list")
    //@ApiOperation(value = "获取流程控制列表")
    @GetMapping("/getAmsAssetProcessList")
    public TableDataInfo getAmsAssetProcessList(AmsAssetProcess amsAssetProcess)
    {
        startPage();
        List<AmsAssetProcess> list = amsAssetProcessService.selectAmsAssetProcessList(amsAssetProcess);
        return getDataTable(list);
    }


    /**
     * 获取流程控制详细信息
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:process:query")
    //@ApiOperation(value = "获取流程控制详情")
    @GetMapping(value = "/getAmsAssetProcessById")
    public AjaxResult getAmsAssetProcessById(@RequestParam("assetProcessId") Long assetProcessId)
    {
        return AjaxResult.success(amsAssetProcessService.selectAmsAssetProcessByAssetProcessId(assetProcessId));
    }

    /**
     * 新增流程控制
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:process:add")
    @Log(title = "流程控制", businessType = BusinessType.INSERT)
    //@ApiOperation(value = "新增流程控制")
    @PostMapping(value = "/addAmsAssetProcess")
    public AjaxResult addAmsAssetProcess(@RequestBody AmsAssetProcess amsAssetProcess)
    {
        return toAjax(amsAssetProcessService.insertAmsAssetProcess(amsAssetProcess));
    }

    /**
     * 修改流程控制
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:process:edit")
    @Log(title = "流程控制", businessType = BusinessType.UPDATE)
    //@ApiOperation(value = "修改流程控制")
    @PostMapping(value = "/editAmsAssetProcess")
    public AjaxResult editAmsAssetProcess(@RequestBody AmsAssetProcess amsAssetProcess)
    {
        return toAjax(amsAssetProcessService.updateAmsAssetProcess(amsAssetProcess));
    }

    /**
     * 删除流程控制
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:process:remove")
    @Log(title = "流程控制", businessType = BusinessType.DELETE)
	@GetMapping("/removeAmsAssetProcesss")
    public AjaxResult removeAmsAssetProcesss(@RequestParam Long[] assetProcessIds)
    {
        return toAjax(amsAssetProcessService.deleteAmsAssetProcessByAssetProcessIds(assetProcessIds));
    }
    @GetMapping("/getAmsAssetProcessNamesForSelect")
    //@ApiOperation(value = "获取流程控制名称列表用于下拉搜索")
    public AjaxResult getAmsAssetProcessNamesForSelect()
    {
        List<AmsAssetProcess> list = amsAssetProcessService.list();//自行加条件
        List<KeyValueVo> resultList = new ArrayList<>();
        for (AmsAssetProcess amsAssetProcess: list ) {
            KeyValueVo vo = new KeyValueVo();
            //vo.setKey(it.getId());
            //vo.setValue(it.getName());
            resultList.add(vo);
        }
        return AjaxResult.success(resultList);
    }
    /**
     * 导出流程控制列表
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:process:export")
    @Log(title = "流程控制", businessType = BusinessType.EXPORT)
    @PostMapping("/exportAmsAssetProcess")
    public String exportAmsAssetProcess(HttpServletResponse response, AmsAssetProcess amsAssetProcess) throws IOException
    {
        List<AmsAssetProcess> list = amsAssetProcessService.selectAmsAssetProcessList(amsAssetProcess);
        ExcelUtil<AmsAssetProcess> util = new ExcelUtil<AmsAssetProcess>(AmsAssetProcess.class);
        util.exportExcel(response, list, "流程控制数据");
        return "";
    }

}
